/**
 * 
 */
package org.tio.sitexxx.web.server.topic;

import java.util.Map;

import org.redisson.api.listener.MessageListener;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.tio.sitexxx.service.vo.ClearHttpCache;
import org.tio.sitexxx.web.server.http.TioSiteHttpServerInterceptor;
import org.tio.utils.json.Json;

import cn.hutool.core.util.StrUtil;

/**
 * @author tanyaowu
 *
 */
public class TopicClearHttpCacheListener implements MessageListener<ClearHttpCache> {
	private static Logger log = LoggerFactory.getLogger(TopicClearHttpCacheListener.class);

	public static final TopicClearHttpCacheListener me = new TopicClearHttpCacheListener();

	/**
	 * 
	 */
	public TopicClearHttpCacheListener() {
	}

	/**
	 * @param args
	 */
	public static void main(String[] args) {
	}

	@Override
	public void onMessage(CharSequence channel, ClearHttpCache msg) {
		String path = msg.getPath();
		if (StrUtil.isBlank(path)) {
			return;
		}

		Map<String, Object> param = msg.getParam();
		Integer userid = msg.getUserid();
		TioSiteHttpServerInterceptor.clearHttpcache(path, param, userid);
		if (log.isInfoEnabled()) {
			log.info("收到通知，已经清除httpcache[{}], param:{}, uid:{}", path, Json.toJson(param), userid);
		}
	}

}
